// Copyright 2022 a.o.smith ALL Rights Reserved
package com.liuxinlong.modules.specialist.controller;

import com.liuxinlong.modules.common.controller.request.BaseReq;
import com.liuxinlong.modules.common.controller.response.BaseResp;
import com.liuxinlong.modules.specialist.service.SpreadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 专家模块首页控制层
 *
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2023年3月31日
 */
@RestController
@RequestMapping("/spread")
public class SpreadController {
    @Autowired
    private SpreadService spreadService;

    /**
     * 查询专家工作首页信息
     *
     * @return 专家工作首页信息
     */
    @PostMapping("page")
    public BaseResp querySpreadInfo() {
        Map<String, Object> dataMap = spreadService.querySpreadInfo();
        BaseResp resp = new BaseResp();
        resp.setRetMessage("查询专家工作首页信息成功！");
        resp.setDataMap(dataMap);
        return resp;
    }

    /**
     * 查询专家工作动态信息
     *
     * @return 专家工作动态信息
     */
    @PostMapping("trends")
    public BaseResp queryTrendsList(@RequestBody BaseReq req) {
        Map<String, Object> queryParam = new HashMap<>();
        queryParam.put("startNum", req.getStartNum());
        queryParam.put("pageSize", req.getPageSize());
        String startTime = "2023-01-01";
        queryParam.put("startTime", startTime);
        List<Map<String, Object>> dataList = spreadService.queryTrendsList(queryParam);
        int totalNum = spreadService.getTrendsCount(queryParam);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("查询专家工作动态信息成功！");
        resp.setDataList(dataList);
        resp.setTotalNum(totalNum);
        return resp;
    }

    /**
     * 查询首页排行信息
     *
     * @return 首页排行信息
     */
    @PostMapping("ranking")
    public BaseResp queryRankingInfo(@RequestBody BaseReq req) {
        Map<String, Object> queryParam = new HashMap<>();
        String startTime = "2023-01-01";
        queryParam.put("startTime", startTime);
        queryParam.put("startNum", req.getStartNum());
        queryParam.put("pageSize", req.getPageSize());
        Map<String, Object> dataMap = spreadService.queryRankingInfo(queryParam);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("查询首页排行信息成功！");
        resp.setDataMap(dataMap);
        return resp;
    }
}
